package com.sxfq.loansupermarket.backsystem.modular.marketing.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.sxfq.loansupermarket.backsystem.common.constant.factory.PageFactory;
import com.sxfq.loansupermarket.backsystem.common.controller.BaseController;
import com.sxfq.loansupermarket.backsystem.modular.basicData.entity.*;
import com.sxfq.loansupermarket.backsystem.core.log.LogManager;
import com.sxfq.loansupermarket.backsystem.core.log.factory.LogTaskFactory;
import com.sxfq.loansupermarket.backsystem.core.shiro.ShiroKit;
import com.sxfq.loansupermarket.backsystem.core.support.HttpKit;
import com.sxfq.loansupermarket.backsystem.core.util.DateUtil;
import com.sxfq.loansupermarket.backsystem.core.util.StringUtil;
import com.sxfq.loansupermarket.backsystem.core.util.ToolUtil;
import com.sxfq.loansupermarket.backsystem.modular.base.SqlMapper;
import com.sxfq.loansupermarket.backsystem.modular.basicData.service.IGetListService;
import com.sxfq.loansupermarket.backsystem.modular.marketing.entity.ReservationsCallInfo;
import com.sxfq.loansupermarket.backsystem.modular.marketing.entity.ReservationsInfo;
import com.sxfq.loansupermarket.backsystem.modular.marketing.entity.SearchReservationsInfo;
import com.sxfq.loansupermarket.backsystem.modular.marketing.entity.TongJiInfo;
import com.sxfq.loansupermarket.backsystem.modular.marketing.service.IReservationsNoArrivedService;
import com.sxfq.loansupermarket.backsystem.modular.tcCenter.entity.DepartmentInfo;
import com.sxfq.loansupermarket.backsystem.modular.tcCenter.service.IConsultantService;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.BufferedOutputStream;
import java.io.OutputStream;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;


/**
 * @author py
 * @Date
 */
@Controller
@RequestMapping("/reservationsNotArrive")
public class ReservationsNotArrivedController extends BaseController {
    @Autowired
    IReservationsNoArrivedService reservationsNoArrivedService;
    @Autowired
    private RedisTemplate redisTemplate;
    @Autowired
    IGetListService getListService;

    @Autowired
    private SqlMapper sqlMapper;

    @Autowired
    IConsultantService service;

    private String PREFIX = "/marketing/reservations/";

    /**
     * 市场部预约管理建档
     */
    @RequestMapping("/list")
    @ResponseBody
    public Object reservationsRecord(SearchReservationsInfo info, HttpServletRequest request) {
        Page<ReservationsInfo> page = new PageFactory<ReservationsInfo>().defaultPage();
        try {
            info.setStartIndex(page.getSize() * (page.getCurrent() - 1));
            info.setLimitIndex(page.getSize());
            page.setCurrent(0);
            List<ReservationsInfo> list = reservationsNoArrivedService.selectPageListByStatusMapWD(page, info);
            if (list.size() == 0) {
                info.setStartIndex(0);
                list = reservationsNoArrivedService.selectPageListByStatusMapWD(page, info);
            }
            page.setRecords(list);
            page.setTotal(reservationsNoArrivedService.getQueryPagesCountWD(page, info));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return super.packForBT(page);
    }

    @RequestMapping(value = "/getcount", method = RequestMethod.GET)
    @ResponseBody
    public int getcount(SearchReservationsInfo info, HttpServletRequest request) {
        return reservationsNoArrivedService.getcount(info);
    }

    /**
     * 未到点击姓名跳转客户管理详情页面
     */
    @RequestMapping(value = "/to_callindetails/{id}")
    public String to_callindetails(@PathVariable String id, Model model) {
        String tableHead = redisTemplate.opsForList().index(ShiroKit.getUser().getAccount()+"Abbreviation",0)+"";
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        if (ToolUtil.isEmpty(id)) {
            return "/errorClose.html";
        }
        try {
            String sql = "select " +
                    "  (CASE a.customer_sex  " +
                    "  WHEN 1 THEN  " +
                    "  '男'  " +
                    "  WHEN 2 THEN  " +
                    "  '女'  " +
                    "  ELSE  " +
                    "  '未知'  " +
                    "  END  " +
                    " ) as sex ,left(a.appointment_time,19) as appointmentTime,left(a.lasthuifangtime,19) as lasthuifangtime," +
                    "left(a.filing_time,19) as filingTime,a.* from reservations_info a where id= '" + id + "' limit 0,1";
            ReservationsInfo reservationsInfo = sqlMapper.selectOne(sql, ReservationsInfo.class);
            if (ShiroKit.getUser().getRefereeShipInfoList() == null) {
                String getListSql = "select id,referee_ship as refereeShip from referee_ship_info order by num asc;";
                List<RefereeShipInfo> refereeShipList = sqlMapper.selectList(getListSql, RefereeShipInfo.class);
                ShiroKit.getUser().setRefereeShipInfoList(refereeShipList);
            }
            if (ShiroKit.getUser().getEconomicAbilityList() == null) {
                String getListSql = "select id, economic_ability from economic_ability_info order by num asc;";
                List<EconomicAbilityInfo> economicAbilityList = sqlMapper.selectList(getListSql, EconomicAbilityInfo.class);
                ShiroKit.getUser().setEconomicAbilityList(economicAbilityList);
            }
            if (ShiroKit.getUser().getDepartmentList() == null) {
                String getListSql = "select a.department as department from " + ShiroKit.getUser().getPay_service_grade_info() + " a where a.is_upper=1 group by a.department order by a.id;";
                List<DepartmentInfo> departmentList=sqlMapper.selectList(getListSql,DepartmentInfo.class);
                ShiroKit.getUser().setDepartmentList(departmentList);
            }
            if (ShiroKit.getUser().getCharactersList() == null) {
                String getListSql = "select id, characters from character_info order by num asc;";
                List<CharacterInfo> charactersList=sqlMapper.selectList(getListSql,CharacterInfo.class);
                ShiroKit.getUser().setCharactersList(charactersList);
            }
            if (ShiroKit.getUser().getOccupationInfoList() == null) {
                String getListSql = "select id, occupation from occupation_info where isshow=1 order by num asc;";
                List<OccupationInfo> occupationList = sqlMapper.selectList(getListSql, OccupationInfo.class);
                ShiroKit.getUser().setOccupationInfoList(occupationList);
            }
            if (ShiroKit.getUser().getGetMedium() == null) {
                List<Map<String, Object>> getMedium = getListService.getMedium();
                ShiroKit.getUser().setGetMedium(getMedium);
            }
            if (ShiroKit.getUser().getConsumptionHabitsList() == null) {
                String getListSql = "select id, consumption_habits from consumption_habits_info order by  num asc;";
                List<ConsumptionHabitsInfo> consumptionHabitsList = sqlMapper.selectList(getListSql, ConsumptionHabitsInfo.class);
                ShiroKit.getUser().setConsumptionHabitsList(consumptionHabitsList);
            }
            model.addAttribute("consumptionHabitsList", ShiroKit.getUser().getConsumptionHabitsList());
            model.addAttribute("refereeShipList", ShiroKit.getUser().getRefereeShipInfoList());
            model.addAttribute("economicAbilityList", ShiroKit.getUser().getEconomicAbilityList());
            model.addAttribute("departmentList",ShiroKit.getUser().getDepartmentList());
            model.addAttribute("charactersList", ShiroKit.getUser().getCharactersList());
            model.addAttribute("occupationList", ShiroKit.getUser().getOccupationInfoList());
            model.addAttribute("reservationsInfo", reservationsInfo);
            model.addAttribute("outpatientManagementList", ShiroKit.getSessionAttr("outpatientManagementList"));
            model.addAttribute("roleName", ShiroKit.getUser().getRoleName());
            model.addAttribute("userName", ShiroKit.getUser().getAccount());
            model.addAttribute("getMedium", ShiroKit.getUser().getGetMedium());
            return PREFIX + "callindetails.html";
        } catch (Exception e) {
            return "/errorClose.html";
        }
    }

    @RequestMapping(value = "/play/{id}")
    public String play(@PathVariable String id, Model model) {
        String sql="select * from reservemoney_call_record where id="+id+";";
        ReservationsCallInfo reservationsCallInfo=sqlMapper.selectOne(sql,ReservationsCallInfo.class);
        model.addAttribute("url", reservationsCallInfo.getRecFile());
        return PREFIX + "play.html";
    }

    @RequestMapping(value = "/play1/{id}")
    public String play1(@PathVariable String id, Model model) {
        String sql="select * from reservemoney_callin_record where id="+id+";";
        ReservationsCallInfo reservationsCallInfo=sqlMapper.selectOne(sql,ReservationsCallInfo.class);
        model.addAttribute("url", reservationsCallInfo.getRecFile());
        return PREFIX + "play.html";
    }

    /**
     * 未到点击姓名跳转客户管理详情页面
     */
    @RequestMapping(value = "/to_reservationsNotDetail/{id}")
    public String to_reservationsNotDetail(@PathVariable String id, Model model) {
        String tableHead = redisTemplate.opsForList().index(ShiroKit.getUser().getAccount()+"Abbreviation",0)+"";
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        if (ToolUtil.isEmpty(id)) {
            return "/errorClose.html";
        }
        try {
            String sql = "select " +
                    "  (CASE a.customer_sex  " +
                    "  WHEN 1 THEN  " +
                    "  '男'  " +
                    "  WHEN 2 THEN  " +
                    "  '女'  " +
                    "  ELSE  " +
                    "  '未知'  " +
                    "  END  " +
                    " ) as sex ,left(a.appointment_time,19) as appointmentTime,left(a.lasthuifangtime,19) as lasthuifangtime," +
                    "left(a.filing_time,19) as filingTime,a.* from reservations_info a where id= '" + id + "' limit 0,1";
            ReservationsInfo reservationsInfo = sqlMapper.selectOne(sql, ReservationsInfo.class);
            if (ShiroKit.getUser().getRefereeShipInfoList() == null) {
                String getListSql = "select id,referee_ship as refereeShip from referee_ship_info order by num asc;";
                List<RefereeShipInfo> refereeShipList = sqlMapper.selectList(getListSql, RefereeShipInfo.class);
                ShiroKit.getUser().setRefereeShipInfoList(refereeShipList);
            }
            if (ShiroKit.getUser().getEconomicAbilityList() == null) {
                String getListSql = "select id, economic_ability from economic_ability_info order by num asc;";
                List<EconomicAbilityInfo> economicAbilityList = sqlMapper.selectList(getListSql, EconomicAbilityInfo.class);
                ShiroKit.getUser().setEconomicAbilityList(economicAbilityList);
            }
            if (ShiroKit.getUser().getDepartmentList() == null) {
                String getListSql = "select a.department as department from " + redisTemplate.opsForList().index(ShiroKit.getUser().getAccount()+"pay_service_grade_info",0) + " a where a.is_upper=1 group by a.department order by a.id;";
                List<DepartmentInfo> departmentList=sqlMapper.selectList(getListSql,DepartmentInfo.class);
                ShiroKit.getUser().setDepartmentList(departmentList);
            }
            if (ShiroKit.getUser().getCharactersList() == null) {
                String getListSql = "select id, characters from character_info order by num asc;";
                List<CharacterInfo> charactersList=sqlMapper.selectList(getListSql,CharacterInfo.class);
                ShiroKit.getUser().setCharactersList(charactersList);
            }
            if (ShiroKit.getUser().getOccupationInfoList() == null) {
                String getListSql = "select id, occupation from occupation_info where isshow=1 order by num asc;";
                List<OccupationInfo> occupationList = sqlMapper.selectList(getListSql, OccupationInfo.class);
                ShiroKit.getUser().setOccupationInfoList(occupationList);
            }
            if (ShiroKit.getUser().getGetMedium() == null) {
                List<Map<String, Object>> getMedium = getListService.getMedium();
                ShiroKit.getUser().setGetMedium(getMedium);
            }
            if (ShiroKit.getUser().getConsumptionHabitsList() == null) {
                String getListSql = "select id, consumption_habits from consumption_habits_info order by  num asc;";
                List<ConsumptionHabitsInfo> consumptionHabitsList = sqlMapper.selectList(getListSql, ConsumptionHabitsInfo.class);
                ShiroKit.getUser().setConsumptionHabitsList(consumptionHabitsList);
            }
            model.addAttribute("consumptionHabitsList", ShiroKit.getUser().getConsumptionHabitsList());
            model.addAttribute("refereeShipList", ShiroKit.getUser().getRefereeShipInfoList());
            model.addAttribute("economicAbilityList", ShiroKit.getUser().getEconomicAbilityList());
            model.addAttribute("departmentList",ShiroKit.getUser().getDepartmentList());
            model.addAttribute("charactersList", ShiroKit.getUser().getCharactersList());
            model.addAttribute("occupationList", ShiroKit.getUser().getOccupationInfoList());
            model.addAttribute("reservationsInfo", reservationsInfo);
            model.addAttribute("outpatientManagementList", ShiroKit.getSessionAttr("outpatientManagementList"));
            model.addAttribute("roleName", redisTemplate.opsForList().index(ShiroKit.getUser().getAccount()+"RoleName",0));
            model.addAttribute("userName", ShiroKit.getUser().getAccount());
            model.addAttribute("getMedium", ShiroKit.getUser().getGetMedium());
            return PREFIX + "reservationsNotDetail.html";
        } catch (Exception e) {
            return "/errorClose.html";
        }
    }

    /**
     * E看牙病历号点亮页面
     */
    @RequestMapping(value = "/reservations_lightenUp/{id}")
    public String reservations_lightenUp(@PathVariable String id, Model model) {
        String tableHead = redisTemplate.opsForList().index(ShiroKit.getUser().getAccount()+"Abbreviation",0)+"";
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        model.addAttribute("id", id);
        return PREFIX + "reservations_lightenUp.html";
    }

    /**
     * 统计查询
     */
    @RequestMapping(value = "/tongji", method = RequestMethod.GET)
    @ResponseBody
    public List<TongJiInfo> change(String param1, String param2, String param3, String param4, String param5, String param6, String param7, String param8,
                                   String param9, String param10, String param11, String param12, String param13, String param14, String param15, String param16) throws Exception {
        //1.获取当前日期，格式为yyyy-MM-dd hh:mm:ss
        String currentDate = DateUtil.getTime(new Date()).substring(0, 10);//取今天的年月日
        //获取昨天日期字符串 格式为yyyy-MM-dd hh:mm:ss
        String lastDate = DateUtil.getAfterDayDate("-1").substring(0, 10);//取昨日 的年月日
        //获取当月的字符串
        String currerntMonth = currentDate.substring(0, 7);//yyyy-mm
        //获取上月日期
        String lastMonth = DateUtil.getAfterDayMonth("-1").substring(0, 7);//取上月的年月
        String contitionInfo = "";
        if (StringUtils.isNotEmpty(param1) && !"请选择".equals(param1)) {
            String outpatientName = "";
            String outpatientName2[] = param1.split(",");
            if (outpatientName2.length == 1) {
                outpatientName = outpatientName2[0];
            } else {
                for (int i = 0; i < outpatientName2.length; i++) {
                    if (i == (outpatientName2.length - 1)) {
                        outpatientName += "'" + outpatientName2[i];
                    } else if (i == 0) {
                        outpatientName += outpatientName2[i] + "'" + ",";
                    } else {
                        outpatientName += "'" + outpatientName2[i] + "'" + ",";
                    }
                }
            }
            contitionInfo += " and t.outpatient_name in ( '" + outpatientName + "') ";
        }
        if (StringUtils.isNotBlank(param2)) {
            contitionInfo += " and t.follower in (select t1.account from user t1 where t1.roleid='" + param2 + "')";
        }
        if (StringUtils.isNotBlank(param3)) {
            contitionInfo += " and t.appointment_pay_service= '" + param3 + "' ";
        }
        if (StringUtils.isNotBlank(param4)) {
            contitionInfo += " and t.archiving= '" + param4 + "' ";
        }
        if (StringUtils.isNotBlank(param5)) {
            contitionInfo += " and t.follower= '" + param5 + "' ";
        }
        if (StringUtils.isNotBlank(param6)) {
            contitionInfo += " and t.access_disease= '" + param6 + "' ";
        }
        if (StringUtils.isNotBlank(param7)) {
            if (!"请选择".equals(param7)) {
                contitionInfo += " and t.one_channel= '" + param7 + "' ";
            }
        }
        if (StringUtils.isNotBlank(param8)) {
            if (!"请选择".equals(param8)) {
                contitionInfo += " and t.two_channel= '" + param8 + "' ";
            }
        }
        if (StringUtils.isNotBlank(param9)) {
            if (!"请选择".equals(param9)) {
                contitionInfo += " and t.thr_channel= '" + param9 + "' ";
            }
        }
        if (StringUtils.isNotEmpty(param10) && !"请选择".equals(param10)) {
            String statuss = "";
            String statuss2[] = param10.split(",");
            if (statuss2.length == 1) {
                statuss = statuss2[0];
            } else {
                for (int i = 0; i < statuss2.length; i++) {
                    if (i == (statuss2.length - 1)) {
                        statuss += "'" + statuss2[i];
                    } else if (i == 0) {
                        statuss += statuss2[i] + "'" + ",";
                    } else {
                        statuss += "'" + statuss2[i] + "'" + ",";
                    }
                }
            }
            contitionInfo += " and t.statuss in ( '" + statuss + "') ";
        }
        if (StringUtils.isNotBlank(param11)) {
            contitionInfo += " and t.filing_time >= '" + param11 + "' ";
        }
        if (StringUtils.isNotBlank(param12)) {
            contitionInfo += " and t.filing_time <= '" + param12 + "' ";
        }
        if (StringUtil.isNotEmpty(param15) && !"请选择".equals(param15)) {
            String area = "";
            String area2[] = param15.split(",");
            if (area2.length == 1) {
                area = area2[0];
            } else {
                for (int i = 0; i < area2.length; i++) {
                    if (i == (area2.length - 1)) {
                        area += "'" + area2[i];
                    } else if (i == 0) {
                        area += area2[i] + "'" + ",";
                    } else {
                        area += "'" + area2[i] + "'" + ",";
                    }
                }
            }
            contitionInfo += " and t.outpatient_name in (select a.simplename from dept a where a.area_abbreviation in ('" + area + "')) ";
        }
        //姓名   电话   微信  预约号
        if (StringUtils.isNotBlank(param16)) {
            contitionInfo += " and (t.customer_name like CONCAT('%" + param16 + "%') or t.customer_phone like CONCAT('%" + param16 + "%') " +
                    " or t.customer_phone2 like CONCAT('%" + param16 + "%') " +
                    " or t.wechat_number like CONCAT('%" + param16 + "%') or t.reservations_num like CONCAT('%" + param16 + "%') " +
                    " or t.identification_number like CONCAT('%" + param16 + "%') or t.key_word like CONCAT('%" + param16 + "%') " +
                    " or t.remarks like CONCAT('%" + param16 + "%') or t.huifang like CONCAT('%" + param16 + "%') " +
                    " or t.szm like CONCAT('%" + param16 + "%')) ";
        }
        contitionInfo += "  group by t.id) t ";
        //查询今日未到
        String sql = "select count(*) as countNum from (select id from reservations_infosc t where left(appointment_time,10) = '" + currentDate + "'and t.status ='预约'" + contitionInfo +
                //查询昨日未到
                " union all select count(*) as countNum from (select id from reservations_infosc t where left(appointment_time,10) = '" + lastDate + "'and t.status ='预约'" + contitionInfo +
                //查询本周未到
                " union all select count(*) as countNum from (select id from reservations_infosc t where appointment_time >='" + param13 + "' and appointment_time <='" + param14 + "' and t.status ='预约'" + contitionInfo +
                //查询当月未到
                " union all select count(*) as countNum from (select id from reservations_infosc t where left(appointment_time,7) = '" + currerntMonth + "'and t.status ='预约'" + contitionInfo +
                //查询上月未到
                " union all select count(*) as countNum from (select id from reservations_infosc t where left(appointment_time,7) = '" + lastMonth + "'and t.status ='预约'" + contitionInfo;
        List<TongJiInfo> tongJiInfoList = sqlMapper.selectList(sql, TongJiInfo.class);
        return tongJiInfoList;
    }

    //市场未到导出
    @RequestMapping(value = "/reservationsExportSCWD")
    public void reservationsExportYD(@Valid SearchReservationsInfo searchInfo, HttpServletResponse response) {
        try {
            List<ReservationsInfo> list = reservationsNoArrivedService.reservationsExportWD(searchInfo);
            // 解析成excel文件
            // 第一步，创建一个webbook，对应一个Excel文件
            HSSFWorkbook wb = new HSSFWorkbook();
            // 第二步，在wb中添加一个sheet,对应Excel文件中的sheet
            HSSFSheet sheet = wb.createSheet("前端导出");
            for (int i = 0; i < 26; i++) {
                sheet.setColumnWidth(i, 24 * 256);
            }
            // 第三步，在sheet中添加表头第0行,注意老版本poi对Excel的行数列数有限制short
            HSSFRow row = sheet.createRow(0);
            // 第四步，创建单元格，并设置值表头 设置表头居中
            HSSFCellStyle style = wb.createCellStyle();
            style.setAlignment(HorizontalAlignment.CENTER);// 创建一个居中格式
            HSSFCell cell = row.createCell(0);
            cell.setCellValue("预约号");
            cell.setCellStyle(style);
            cell = row.createCell(1);
            cell.setCellValue("姓名");
            cell.setCellStyle(style);
            cell = row.createCell(2);
            cell.setCellValue("手机号码");
            cell.setCellStyle(style);
            cell = row.createCell(3);
            cell.setCellValue("预约门诊");
            cell.setCellStyle(style);
            cell = row.createCell(4);
            cell.setCellValue("回访状态");
            cell.setCellStyle(style);
            cell = row.createCell(5);
            cell.setCellValue("预约时间");
            cell.setCellStyle(style);
            cell = row.createCell(6);
            cell.setCellValue("建档人");
            cell.setCellStyle(style);
            cell = row.createCell(7);
            cell.setCellValue("跟进人");
            cell.setCellStyle(style);
            cell = row.createCell(8);
            cell.setCellValue("建档时间");
            cell.setCellStyle(style);
            cell = row.createCell(9);
            cell.setCellValue("一级渠道");
            cell.setCellStyle(style);
            cell = row.createCell(10);
            cell.setCellValue("二级渠道");
            cell.setCellStyle(style);
            cell = row.createCell(11);
            cell.setCellValue("三级渠道");
            cell.setCellStyle(style);
            cell = row.createCell(12);
            cell.setCellValue("回访");
            cell.setCellStyle(style);
            cell = row.createCell(13);
            cell.setCellValue("性别");
            cell.setCellStyle(style);
            cell = row.createCell(14);
            cell.setCellValue("年龄");
            cell.setCellStyle(style);
            cell = row.createCell(15);
            cell.setCellValue("预约病种");
            cell.setCellStyle(style);
            cell = row.createCell(16);
            cell.setCellValue("访问病种");
            cell.setCellStyle(style);
            cell = row.createCell(17);
            cell.setCellValue("关键词");
            cell.setCellStyle(style);
            cell = row.createCell(18);
            cell.setCellValue("微信号");
            cell.setCellStyle(style);
            // 填充数据
            for (int i = 0; i < list.size(); i++) {
                ReservationsInfo map = list.get(i);
                row = sheet.createRow(i + 1);
                // 第四步，创建单元格，并设置值
                for (int j = 0; j <= 18; j++) {
                    row.createCell(j).setCellStyle(style);
                }
                row.getCell(0).setCellValue(map.getReservationsNum());
                row.getCell(1).setCellValue(map.getCustomerName());
                if (Integer.parseInt(redisTemplate.opsForList().index(ShiroKit.getUser().getAccount()+"PhonePrivilegesexp",0)+"") == 1) {
                    row.getCell(2).setCellValue(map.getCustomerPhone());
                } else {
                    row.getCell(2).setCellValue("无");
                }
                row.getCell(3).setCellValue(map.getOutpatientName());
                row.getCell(4).setCellValue(map.getStatuss());
                row.getCell(5).setCellValue(map.getAppointmentTime());
                row.getCell(6).setCellValue(map.getArchiving());
                row.getCell(7).setCellValue(map.getFollower());
                row.getCell(8).setCellValue(map.getFilingTime());
                row.getCell(9).setCellValue(map.getOneChannel());
                row.getCell(10).setCellValue(map.getTwoChannel());
                row.getCell(11).setCellValue(map.getThrChannel());
                row.getCell(12).setCellValue(map.getHuifang());
                row.getCell(13).setCellValue(map.getSex());
                row.getCell(14).setCellValue(map.getCustomerAge());
                row.getCell(15).setCellValue(map.getAppointmentPayService());
                row.getCell(16).setCellValue(map.getAccessDisease());
                row.getCell(17).setCellValue(map.getKeyWord());
                row.getCell(18).setCellValue(map.getWechatNumber());
            }
            String date = new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new java.util.Date());
            String filename = "data" + date + ".xls";
            response.setHeader("Content-Disposition",
                    "attachment; filename=\"" + URLEncoder.encode(filename, "UTF-8") + "\"");
            response.setContentType("application/octet-stream;charset=UTF-8");
            OutputStream outputStream = new BufferedOutputStream(response.getOutputStream());
            wb.write(outputStream);
            outputStream.flush();
            outputStream.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}